package com.tensquare.qa.dao;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.qa.pojo.Problem;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
//SQL查询
public interface ProblemDao extends JpaRepository<Problem,String>,JpaSpecificationExecutor<Problem>{
    //最新
    //是否使用原生SQL语句查询 nativeQuery = true
    @Query(value = "select * from tb_problem where id in (select problemid from tb_pl where labelid = ?1) order by replytime desc",nativeQuery = true)
    public List<Problem> newList(String labelid, PageRequest pageRequest);

    //热门
    @Query(value = "select * from tb_problem where id in (select problemid from tb_pl where labelid = ?1) order by reply desc",nativeQuery = true)
    public List<Problem> hotList(String labelid, PageRequest pageRequest);

    //等待
    @Query(value = "select * from tb_problem where id in (select problemid from tb_pl where labelid = ?1) and reply = 0 order by createtime desc",nativeQuery = true)
    public List<Problem> waitList(String labelid, PageRequest pageRequest);

}
